
from sqlalchemy import Column, Integer, String, Float, DateTime, UniqueConstraint, Boolean

from QualityInspectionViolation.Model.Appeal import Base


class ViolationRecord(Base):
    __tablename__ = 'violation_record'
    id = Column(Integer, primary_key=True)
    customerId = Column(Integer)
    customerName = Column(String(32))
    adviserId = Column(Integer)
    adviserName = Column(String(32))
    callId = Column(Integer)
    context = Column(String(10240))
    adopt = Column(Boolean)
    createdAt = Column(DateTime)
    updatedAt = Column(DateTime)

    def queryViolationRecordCountByAdviser(self, customerId, violationRecordId, session):
        count = session.query(ViolationRecord).\
            filter(ViolationRecord.id != violationRecordId).\
            filter(ViolationRecord.customerId == customerId).\
            filter(ViolationRecord.adopt == False).\
            count()

        print("ViolationRecordCount：", count)
        return count

    def updateViolationRecord(self, violationRecordId, session):
        appeal = session.query(ViolationRecord).\
            filter(ViolationRecord.id == violationRecordId).update({"adopt": True})
        return appeal
